#include <stdio.h>
#include <math.h>
#define n 3

int main() {
    float eq[n][n + 1] = {1, 1, 1, 6, 0, 4, -1, 5, 2, -2, 1, 1};
    float tmp, x[n], sum;
    int i, j, k, pos;

    for (j = 0; j < n; j++) {
        for (i = 0; i < n; i++) {
            if (i > j) {
                tmp = eq[i][j]/eq[j][j];
                for (k = 0; k <=n; k++) {
                    eq[i][k] = eq[i][k] - tmp * eq[j][k];
                }
            }
        }
    }

    i = n - 1;
    x[i] = eq[i][n] / eq[i][i];
    for (i = n - 2; i >= 0; i--) {
        sum = 0.0;
        for (j = i + 1; j < n; j++) {
            sum += eq[i][j] * x[j];
        }
        x[i] = (eq[i][n] - sum) / eq[i][i];
    }

    for (i = 0; i < n; i++) {
        printf("x%d = %f ", i+1, x[i]);
    }
    printf("\n");

    return 0;
}
